'use strict';
/**
 * Module dependencies.
 */
require('./config/init')();
const logger = require('./app/util/logger');
const config = require('./config/config');
const express = require('./config/express');
import series from 'async/series';
import fs from 'fs';
const lodash = require('lodash');
const server = express();
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
const files = fs.readdirSync('./app/models');
const uri=config.mongoDb.uri;

mongoose.connect(uri);
mongoose.connection.on('error', function() {
    console.error('MongoDB Connection Error. Make sure MongoDB is running.');
    throw new Error('mongoStatusError');
});
mongoose.connection.once('open', function() {
    console.log('open mongodb success:'+uri);
    lodash.each(files, (file) => {
        if (!/.js$/.test(file)) {
            return;
        }
        let modelName = file.replace('.js', '');
        console.log('load model:', modelName);
        require(`./app/models/`+modelName);
    });
    server.listenAsync(config.port).then(()=>{
        logger.info('Application started on port ', config.port);
    });
});
export default server;













